package com.zxy.ziems.server.classify.pojo.vo;

import com.zxy.ziems.server.utils.tree.TreeInterface;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author bhg
 * @date 2023/3/15
 */
@Data
public class ClassifyTreeNode implements TreeInterface<ClassifyTreeNode> {

    /**
     * treeId
     */
    private String treeId;

    /**
     * 类ID
     */
    private String classifyId;

    /**
     * 分类名称
     */
    private String classifyName;

    /**
     * 父分类ID
     */
    private String parentClassifyId;

    /**
     * 排序号
     */
    private Integer sort;

    /**
     * 计算方式：0.下级分类合计，1.下级点位合计
     */
    private Integer countType;

    /**
     * 根节点分类id
     */
    private String rootClassifyId;

    /**
     * 数据获取类型，0.手动(天)，1.手动（月）2.自动
     */
    private Integer dataObtainType;

    /**
     * 子集
     */
    private List<ClassifyTreeNode> children = new ArrayList<>();

    /**
     * 类型：0-分类；1-设备
     */
    private Integer type;

    /**
     * 描述
     */
    private String description;

    public ClassifyTreeNode() {
    }

    public ClassifyTreeNode(String classifyId, String classifyName, String parentClassifyId, Integer sort, Integer countType,
                            String rootClassifyId, Integer dataObtainType, String description, Integer type) {
        this.treeId = classifyId;
        String[] split = classifyId.split("-");
        if (split.length > 1) {
            this.classifyId = split[1];
        } else {
            this.classifyId = classifyId;
        }
        this.classifyName = classifyName;
        this.parentClassifyId = parentClassifyId;
        this.sort = sort;
        this.countType = countType;
        this.rootClassifyId = rootClassifyId;
        this.dataObtainType = dataObtainType;
        this.type = type;
        this.description = description;
    }

    public ClassifyTreeNode(String classifyId, String classifyName, String parentClassifyId, Integer type) {
        this.treeId = classifyId;
        String[] split = classifyId.split("-");
        if (split.length > 1) {
            this.classifyId = split[1];
        } else {
            this.classifyId = classifyId;
        }
        this.classifyName = classifyName;
        this.parentClassifyId = parentClassifyId;
        this.type = type;
    }

    @Override
    public String _getTreeCode() {
        return treeId;
    }

    @Override
    public String _getTreeParentCode() {
        return parentClassifyId;
    }

    @Override
    public void _setTreeChildren(List<ClassifyTreeNode> list) {
        setChildren(list);
    }

    @Override
    public List<ClassifyTreeNode> _getTreeChildren() {
        return children;
    }
}
